<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */

class Minime_User_Subscriptions_Loader {
    
    private $conf;
    
    public function __construct(Array $conf) {
        if(!is_readable($conf['datastore']['user'])) {
            throw new Exception("Configured path where user subscriptions suppose to exist (" . $conf['datastore']['user'] . ") is not readable!");
        }
        $this->conf = $conf;
    }
    
    /**
     * 
     * @param String $username
     * @return Minime_User_Subscriptions
     */
    public function getSubscriptions($username) {
        $filename = $this->conf['datastore']['user'] . '/' . $username . '/subscriptions.xml';
        if(!is_readable($filename)) {
            throw new Exception("Could not read file '" . $filename . "'! User does not exists?");
            //return null;
        }
        return Minime_User_Subscriptions::buildFromRawXML(file_get_contents($filename));
    }
    
}